﻿<%@ Page Language="VB" Debug="true" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    Sub Page_Load()
        Dim ConnectionString As String = ConfigurationSettings.AppSettings("strcnn")
        Dim strsql As String
        Dim myConnection As New OleDbConnection(ConnectionString)
        Dim myCommand as New OleDbCommand
        Dim myDataReader as OleDbDataReader
        myConnection.Open()
        myCommand.Connection = myConnection
    
        strsql = "SELECT Pedido.*, Cliente.*, Fabrica.ID, Fabrica.RazaoSocial, Transportadora.ID, Transportadora.RazaoSocial, Vendedor.ID, Vendedor.Sigla FROM Vendedor INNER JOIN (Transportadora INNER JOIN (Fabrica INNER JOIN (Cliente INNER JOIN Pedido ON Cliente.ID = Pedido.IDCliente) ON Fabrica.ID = Pedido.IDFabrica) ON Transportadora.ID = Pedido.IDTransportadora) ON Vendedor.ID = Pedido.IDVendedor WHERE pedido.codigojolitex=" & Request("ID")
        myCommand.CommandText = strsql
        myDataReader = myCommand.ExecuteReader()
        myDataReader.Read()
        Sincronizado.Visible = not myDataReader("Sincronizado")
        if myDataReader("Cliente.CodigoJolitex") = "" then
            CodigoCliente.Text = "CLIENTE NÃO CADASTRADO"
        else
            CodigoCliente.Text = myDataReader("Cliente.CodigoJolitex")
        end if
        RazaoSocial.Text = myDataReader("Cliente.RazaoSocial")
        Regiao.Text = myDataReader("Regiao")
        Endereco.Text = myDataReader("Endereco")
        Bairro.Text = myDataReader("Bairro")
        CEP.Text = myDataReader("CEP")
        Cidade.Text = myDataReader("Cidade")
        UF.Text = myDataReader("Estado")
        CNPJ.Text = myDataReader("CNPJ")
        InscricaoEstadual.Text = myDataReader("InscricaoEstadual")
        EnderecoEntrega.Text = myDataReader("EnderecoEntrega")
        BairroEntrega.Text = myDataReader("BairroEntrega")
        EnderecoCobranca.Text = myDataReader("EnderecoCobranca")
        BairroCobranca.Text = myDataReader("BairroCobranca")
        Observacao.Text = Replace(myDataReader("Pedido.Observacao"), Chr(13), "<br>")
        Transportadora.Text = myDataReader("Transportadora.RazaoSocial")
        Data.Text = Format(myDataReader("Data"), "dd/MM/yy")
        Data2.Text = Data.Text
        NumeroPedido.Text = myDataReader("Pedido.CodigoJolitex")
        NumeroPedido2.Text = NumeroPedido.Text
        CondicaoPagamento.Text = myDataReader("CondicaoPagamento")
        DataEntrega.Text = myDataReader("PrazoEntrega")
        Quantidade.Text = myDataReader("Pecas")
        Telefone.Text = myDataReader("Telefone")
        Dim Desc
        Try
            Desc = myDataReader("Desconto") / 100
        Catch
            Desc = 0
        End Try
        Desconto.Text = Desc * 100
        myDataReader.Close()
    
        strsql = "select sum(quantidade*precounitario) as total from pedido, produto where pedido.id=produto.idpedido and codigojolitex=" & Request("ID")
        myCommand.CommandText = strsql
        myDataReader = myCommand.ExecuteReader()
        myDataReader.Read()
        Dim ValMerc = myDataReader("Total")
        myDataReader.Close()
        TotalMercadoria.Text = Format(ValMerc, "#.00")
        Dim ValDesc = ValMerc * Desc
        ValorDesconto.Text = Format(ValDesc, "#0.00")
    
        strsql = "select sum(" & Replace(1-Desc, ",", ".") & "*quantidade*precounitario*iif(descricao like '%tap%' or descricao like '%banh%', 0.1, 0)) as total from pedido, produto where pedido.id=produto.idpedido and codigojolitex=" & Request("ID")
        myCommand.CommandText = strsql
        myDataReader = myCommand.ExecuteReader()
        myDataReader.Read()
        Dim ValIpi = myDataReader("Total")
        myDataReader.Close()
        ValorIpi.Text = iif(ValIpi=0, "0,00", Format(ValIpi, "#.00"))
    
        TotalLiquido.Text = Format(ValMerc - ValDesc + ValIpi, "#.00")
    
        strsql = "select * from produto, pedido where pedido.id=produto.idpedido and codigojolitex=" & Request("ID")
        myCommand.CommandText = strsql
        Tabela.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
        Tabela.DataBind()
    End Sub

</script>
<html>
<head>
    <link href="imprimir.css" type="text/css" rel="stylesheet" />
</head>
<body leftmargin="0" topmargin="0" arial="arial">
    <table cellspacing="0" cellpadding="5" width="933" border="0">
        <tbody>
            <tr>
                <td colspan="3">
                    <table height="83" cellspacing="0" cellpadding="0" width="933" border="0">
                        <tbody>
                            <tr>
                                <td width="80" height="83">
                                    <img height="83" src="urso.jpg" width="80" /></td>
                                <td align="middle" width="619">
                                    <h3><asp:Label id="Sincronizado" runat="server">PEDIDO NEGOCIADO</asp:Label>
                                    </h3>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table cellspacing="0" cellpadding="0" width="933" border="0">
                        <tbody>
                            <tr>
                                <td width="33%">
                                    Código do cliente: <asp:Label id="CodigoCliente" runat="server"></asp:Label></td>
                                <td width="33%">
                                    Razão social: <asp:Label id="RazaoSocial" runat="server"></asp:Label></td>
                                <td width="33%">
                                    Representante: ZT Representaç&otilde;es Comerciais Ltda. 
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <table cellspacing="0" cellpadding="0" width="933" border="0">
                        <tbody>
                            <tr>
                                <td width="33%">
                                    Região: <asp:Label id="Regiao" runat="server"></asp:Label></td>
                                <td width="33%">
                                    Endereço: <asp:Label id="Endereco" runat="server"></asp:Label></td>
                                <td width="33%">
                                    Bairro: <asp:Label id="Bairro" runat="server"></asp:Label></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <table cellspacing="0" cellpadding="0" width="933" border="0">
                        <tbody>
                            <tr>
                                <td width="33%">
                                    CEP: <asp:Label id="CEP" runat="server"></asp:Label></td>
                                <td width="33%">
                                    Cidade: <asp:Label id="Cidade" runat="server"></asp:Label></td>
                                <td width="33%">
                                    UF: <asp:Label id="UF" runat="server"></asp:Label></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <table cellspacing="0" cellpadding="0" width="933" border="0">
                        <tbody>
                            <tr>
                                <td width="33%">
                                    CNPJ: <asp:Label id="CNPJ" runat="server"></asp:Label></td>
                                <td width="33%">
                                    Inscrição estadual: <asp:Label id="InscricaoEstadual" runat="server"></asp:Label></td>
                                <td width="33%">
                                    Telefone: <asp:Label id="Telefone" runat="server"></asp:Label></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <table cellspacing="0" cellpadding="0" width="933" border="0">
                        <tbody>
                            <tr>
                                <td width="66%">
                                    Endereço entrega: <asp:Label id="EnderecoEntrega" runat="server"></asp:Label></td>
                                <td width="33%">
                                    Bairro entrega: <asp:Label id="BairroEntrega" runat="server"></asp:Label></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <table cellspacing="0" cellpadding="0" width="933" border="0">
                        <tbody>
                            <tr>
                                <td width="66%">
                                    Endereço cobrança: <asp:Label id="EnderecoCobranca" runat="server"></asp:Label></td>
                                <td width="33%">
                                    Bairro cobrança: <asp:Label id="BairroCobranca" runat="server"></asp:Label></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <table cellspacing="0" cellpadding="0" width="933" border="0">
                        <tbody>
                            <tr>
                                <td width="66%">
                                    Observações: <asp:Label id="Observacao" runat="server"></asp:Label></td>
                                <td valign="top" width="33%">
                                    Transportadora: <asp:Label id="Transportadora" runat="server"></asp:Label></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <table height="50" cellspacing="0" cellpadding="0" width="933" border="0">
                        <tbody>
                            <tr>
                                <td width="30%" height="50">
                                    <table bordercolor="#000000" cellspacing="0" cellpadding="4" border="1">
                                        <tbody>
                                            <tr align="middle" bgcolor="#cccccc">
                                                <td>
                                                    <strong>Data do pedido </strong></td>
                                                <td>
                                                    <strong>Número do pedido </strong></td>
                                            </tr>
                                            <tr align="middle">
                                                <td>
                                                    <strong><asp:Label id="Data" runat="server"></asp:Label></strong></td>
                                                <td>
                                                    <strong><asp:Label id="NumeroPedido" runat="server"></asp:Label></strong></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </td>
                                <td width="20%">
                                    <asp:Label id="Desconto" runat="server"></asp:Label>% Desconto 
                                </td>
                                <td width="25%">
                                    Condição de pagamento: <asp:Label id="CondicaoPagamento" runat="server"></asp:Label></td>
                                <td width="25%">
                                    Data de entrega: <asp:Label id="DataEntrega" runat="server"></asp:Label></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <br />
                    <asp:DataGrid id="Tabela" runat="server" Width="100%" CellPadding="2" BorderColor="Black" BorderWidth="1px" AutoGenerateColumns="False">
                        <HeaderStyle font-bold="True"></HeaderStyle>
                        <Columns>
                            <asp:BoundColumn DataField="Codigo" HeaderText="C&#243;digo" HeaderStyle-BackColor="#CCCCCC"></asp:BoundColumn>
                            <asp:BoundColumn DataField="Descricao" HeaderText="Descri&#231;&#227;o" HeaderStyle-BackColor="#CCCCCC"></asp:BoundColumn>
                            <asp:BoundColumn DataField="PrecoUnitario" HeaderText="Pre&#231;o unit&#225;rio" DataFormatString="{0,10:C}" HeaderStyle-BackColor="#CCCCCC"></asp:BoundColumn>
                            <asp:BoundColumn DataField="Quantidade" HeaderText="Quantidade" HeaderStyle-BackColor="#CCCCCC"></asp:BoundColumn>
                        </Columns>
                    </asp:DataGrid>
                    <br />
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <table bordercolor="#000000" cellspacing="0" cellpadding="4" width="933" border="1">
                        <tbody>
                            <tr align="middle" bgcolor="#cccccc">
                                <td>
                                    <strong>Quantidade de produtos </strong></td>
                                <td>
                                    <strong>Total da mercadoria </strong></td>
                                <td>
                                    <strong>Valor do desconto </strong></td>
                                <td>
                                    <strong>Valor do Ipi </strong></td>
                                <td>
                                    <strong>Valor total líquido </strong></td>
                            </tr>
                            <tr align="middle">
                                <td>
                                    <asp:Label id="Quantidade" runat="server"></asp:Label></td>
                                <td>
                                    R$ <asp:Label id="TotalMercadoria" runat="server"></asp:Label></td>
                                <td>
                                    R$ <asp:Label id="ValorDesconto" runat="server"></asp:Label></td>
                                <td>
                                    R$ <asp:Label id="ValorIpi" runat="server"></asp:Label></td>
                                <td>
                                    R$ <asp:Label id="TotalLiquido" runat="server"></asp:Label></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <br />
                    <br />
                    <table width="100%">
                        <tbody>
                            <tr>
                                <td>
                                    <table bordercolor="#000000" cellspacing="0" cellpadding="4" width="70%" border="1">
                                        <tbody>
                                            <tr align="middle" bgcolor="#ffffff">
                                                <td>
                                                    <strong>Crédito</strong></td>
                                                <td>
                                                    <strong>Vendas</strong></td>
                                                <td>
                                                    <strong>Recepção</strong></td>
                                                <td>
                                                    <strong>Digitação</strong></td>
                                            </tr>
                                            <tr valign="bottom" align="middle">
                                                <td>
                                                    <br />
                                                    <br />
                                                    <br />
                                                    <br />
                                                    Data / Visto</td>
                                                <td>
                                                    Data / Visto</td>
                                                <td>
                                                    Data / Visto</td>
                                                <td>
                                                    Data / Visto</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </td>
                                <td>
                                    <table bordercolor="#000000" cellspacing="0" cellpadding="4" border="1">
                                        <tbody>
                                            <tr align="middle" bgcolor="#cccccc">
                                                <td>
                                                    <strong>Data do pedido </strong></td>
                                                <td>
                                                    <strong>Número do pedido </strong></td>
                                            </tr>
                                            <tr align="middle">
                                                <td>
                                                    <strong><asp:Label id="Data2" runat="server"></asp:Label></strong></td>
                                                <td>
                                                    <strong><asp:Label id="NumeroPedido2" runat="server"></asp:Label></strong></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
</body>
</html>
